﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using ProtoGame.GameLib.Entities;

namespace ProtoGame.GameLib
{
    public abstract class TriggerArea<TEventArgs> : Entity where TEventArgs : EventArgs
    {
        int width;
        int height;

        public event EventHandler<TEventArgs> Triggered;

        public TriggerArea(Rectangle triggerArea)
        {
            Position = new Vector2(triggerArea.X, triggerArea.Y);
            width = triggerArea.Width;
            height = triggerArea.Height;
        }

        protected void OnTriggered(object sender, TEventArgs e)
        {
            if (Triggered != null)
                Triggered(sender, e);
        }

        public override Rectangle Bounds
        {
            get { return new Rectangle((int)Position.X, (int)Position.Y, width, height); }
        }

        public override bool DoCheckCollision(Entity otherEntity)
        {
            return Bounds.Intersects(otherEntity.Bounds);
        }
    }
}
